﻿using Abp.Runtime.Session;
using Abp.Timing.Timezone;
using KDS.Mes.DataExporting.Excel.EpPlus;
using KDS.Mes.Dto;
using KDS.Mes.Mes.AlcCodeDetails.Dtos;
using System.Collections.Generic;

namespace KDS.Mes.Mes.AlcCodeDetails
{
    /// <summary>
    /// ALCCode信息的导出EXCEL功能的实现
    /// </summary>
    public class AlcCodeDetailListExcelExporter : EpPlusExcelExporterBase, IAlcCodeDetailListExcelExporter
    {
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;

        /// <summary>
        /// 构造方法
        /// </summary>
        public AlcCodeDetailListExcelExporter(ITimeZoneConverter timeZoneConverter, IAbpSession abpSession)
        {
            _timeZoneConverter = timeZoneConverter;
            _abpSession = abpSession;
        }

        /// <summary>
        /// 导出ALCCode信息到EXCEL文件
        /// <param name="alcCodeDetailListDtos">导出信息的DTO</param>
        /// </summary>
        public FileDto ExportAlcCodeDetailToFile(List<AlcCodeDetailListDto> alcCodeDetailListDtos)
        {
            var file = CreateExcelPackage("alcCodeDetailList.xlsx", excelPackage =>
            {
                var sheet = excelPackage.Workbook.Worksheets.Add(L("AlcCodeDetail"));
                sheet.OutLineApplyStyle = true;

                AddHeader(
                    sheet,
                      L("AlcCodeId"),
 L("SeatPositionId"),
 L("BackrestAssemblyNo"),
 L("CushionAssemblyNo"),
 L("BackrestCoverNo"),
 L("CushionCoverNo"),
 L("BackrestFoamNo"),
 L("CushionFoamNo"),
 L("BackFrameNo"),
 L("SABNo"),
 L("HeadrestNo"),
 L("CenterHeadrestNo"),
 L("ArmRestNo"),
 L("BuckleNo"),
 L("BackplaneNo"),
 L("AdjusterNo"),
 L("AdjusterPlateNo"),
 L("CushioSsupportNo"),
 L("SeatColor"),
 L("PlasticColor"),
 L("MaterialId"),
 L("Slide"),
 L("HGIT"),
 L("LumbarSupport"),
 L("Warmer"),
 L("Ventlation"),
 L("SAB"),
 L("BackPocket"),
 L("SBR"),
 L("IMS"),
 L("OneTouch"),
 L("LastModificationTime"),
 L("CreationTime")
                    );
                AddObjects(sheet, 2, alcCodeDetailListDtos,

             _ => _.AlcCodeId,

             _ => _.SeatPositionId,

             _ => _.BackrestAssemblyNo,

             _ => _.CushionAssemblyNo,

             _ => _.BackrestCoverNo,

             _ => _.CushionCoverNo,

             _ => _.BackrestFoamNo,

             _ => _.CushionFoamNo,

             _ => _.BackFrameNo,

             _ => _.SABNo,

             _ => _.HeadrestNo,

             _ => _.CenterHeadrestNo,

             _ => _.ArmRestNo,

             _ => _.BuckleNo,

             _ => _.BackplaneNo,

             _ => _.AdjusterNo,

             _ => _.AdjusterPlateNo,

             _ => _.CushioSsupportNo,

             _ => _.SeatColor,

             _ => _.PlasticColor,

             _ => _.MaterialId,

             _ => _.Slide,

             _ => _.HGIT,

             _ => _.LumbarSupport,

             _ => _.Warmer,

             _ => _.Ventlation,

             _ => _.SAB,

             _ => _.BackPocket,

             _ => _.SBR,

             _ => _.IMS,

             _ => _.OneTouch,

        _ => _timeZoneConverter.Convert(_.LastModificationTime, _abpSession.TenantId, _abpSession.GetUserId()),
        _ => _timeZoneConverter.Convert(_.CreationTime, _abpSession.TenantId, _abpSession.GetUserId())
       );
                //写个时间转换的吧
                //var creationTimeColumn = sheet.Column(10);
                //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

                for (var i = 1; i <= 33; i++)
                {
                    sheet.Column(i).AutoFit();
                }
            });
            return file;
        }
    }
}